<?php
//Note : even if $entry is not exist, Facebook doesn't provide any error or message
function callGraphAPI($entry){
    
    global $facebook;
    
    $data = null;
    if(!empty($entry)){
        try{
            $now = time();
            $data = $facebook->api($entry);
            error_log("callGraphAPI(".$entry.") success : ".(time() - $now));
        }catch(FacebookApiException $e){
            error_log("callGraphAPI(".$entry.") fail : ".(time() - $now));
            throw $e;
        }
    }
    return $data;    
}

function callFQL($query){

    global $facebook;

    $data = null;
    if(!empty($query)){
        try{
            $now = time();
            $data = $facebook->api(array(
                'method' => 'fql.query',
                'query' => $query
            ));
            error_log("callFQL(".$query.") success : ".(time() - $now));
        }catch(FacebookApiException $e){
            error_log("callFQL(".$query.") fail : ".(time() - $now));
            throw $e;
        }
    }
    return $data;

}

//Note : even if $entry is not exist, Facebook doesn't provide any error or message
function callMultiFQL($queries){
    
    global $facebook;

    $data = null;
    if(!empty($queries) && is_array($queries)){
        try{
            $now = time();
            $data = $facebook->api(
                array(
                	'method' => 'fql.multiquery',
                    'queries' => $queries
                )
            );
            error_log("callMultiFQL(".substr(print_r($queries, true),0,50).") success : ".(time() - $now));
        }catch(FacebookApiException $e){
            error_log("callMultiFQL(".substr(print_r($queries, true),0,50).") fail : ".(time() - $now));
            throw $e;
        }
    }
    return $data;   
}